package com.heima.article.controller.v1;

import com.heima.article.service.ArticleService;
import com.heima.model.article.dtos.ArticleBehaviorDto;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.common.constants.ArticleConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.user.dtos.ReadDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ybw
 * @version 1.0
 * @date 2021/12/11 21:12
 */
@RestController
@RequestMapping("/api/v1/article")
public class ArticleController {
  @Autowired private ArticleService articleService;
  /**
   * 文章列表
   *
   * @param articleHomeDto
   * @return
   */
  @PostMapping("/load")
  public ResponseResult load(@RequestBody ArticleHomeDto articleHomeDto) {
    ResponseResult result =
        articleService.loadList(ArticleConstants.LOADTYPE_LOAD_MORE, articleHomeDto);
    return result;
  }

  /**
   * 加载更多
   *
   * @param articleHomeDto
   * @return
   */
  @PostMapping("/loadmore")
  public ResponseResult loadmore(@RequestBody ArticleHomeDto articleHomeDto) {
    ResponseResult result =
        articleService.loadList(ArticleConstants.LOADTYPE_LOAD_MORE, articleHomeDto);
    return result;
  }

  /**
   * 加载最新
   *
   * @param articleHomeDto
   * @return
   */
  @PostMapping("/loadnew")
  public ResponseResult loadnew(@RequestBody ArticleHomeDto articleHomeDto) {
    ResponseResult result =
        articleService.loadList(ArticleConstants.LOADTYPE_LOAD_NEW, articleHomeDto);
    return result;
  }

  /**
   * 加载文章行为
   * @param dto
   * @return
   */
  @PostMapping("/load_article_behavior")
  public ResponseResult loadArticleBehavior(@RequestBody ArticleBehaviorDto dto){
    return articleService.loadArticleBehavior(dto);
  }
}
